//
//  TSShopImageCell.m
//  项目
//
//  Created by 唐硕 on 16/2/29.
//  Copyright © 2016年 唐硕. All rights reserved.
//

#import "TSShopImageCell.h"
#import "TSMenuBtnView.h"
@interface TSShopImageCell ()<UIScrollViewDelegate>

@end

@implementation TSShopImageCell


+(instancetype)cellWithTableView:(UITableView *)tableView menuArray:(NSMutableArray *)menuArray {
    static NSString *cellID1 = @"tangshuoqweqwqeqeqe";
    TSShopImageCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID1];
    if(cell == nil) {
        cell = [[TSShopImageCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID1 menuArray:menuArray];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier menuArray:(NSArray *)menuArray{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self) {
        UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, Screen_Width, 180)];
        scrollView.contentSize = CGSizeMake(Screen_Width*menuArray.count, self.frame.size.height);
        scrollView.showsHorizontalScrollIndicator = NO;
        //scrollView.pagingEnabled = YES;
        [self addSubview:scrollView];
        
        UIView *backView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_Width*menuArray.count/3, self.frame.size.height)];
        backView.backgroundColor =  [UIColor colorWithRed:244.0/255.0 green:244.0/255.0 blue:244.0/255.0 alpha:0.1];
        //[scrollView addSubview:backView];
        for(int i = 0; i < menuArray.count; i ++) {
            _model = menuArray[i];
            CGRect frame = CGRectMake(i * Screen_Width/3.0, 0, Screen_Width/3, 180 - 20);
            TSMenuBtnView *btnView = [[TSMenuBtnView alloc]initWithFrame3:frame name:_model.commdityname price:[NSString stringWithFormat:@"%.1f",_model.price] imagestr:_model.imageurl];
            btnView.tag = 10000 + i;
            [scrollView addSubview:btnView];
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(act:)];
            [btnView addGestureRecognizer:tap];

        }
    }
    return self;
}
 

- (void)act:(UITapGestureRecognizer *)sender{
    if (self.delegate && [self.delegate respondsToSelector:@selector(choseTerm:)]) {
        
        [self.delegate choseTerm:sender];
        NSLog(@"tag:%ld",sender.view.tag);
    }
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}


@end
